//
//  SearchView.m
//  SmileRead
//
//  Created by dllo on 15/8/29.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "SearchView.h"
#import "Path.h"

@interface SearchView ()<UITextFieldDelegate>

@property (nonatomic, retain) UITextField *textfield;

@property (nonatomic, retain) UIButton *button;

@end


@implementation SearchView

- (instancetype)initWithFrame:(CGRect)frame
{
    self =  [super initWithFrame:frame];
    if (self) {
        
        [self createSubView];
        
    }
    return self;
}

- (void)createSubView
{
    self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(10 * widthFit, 5 * heightFit, self.frame.size.width - 80 * widthFit, self.frame.size.height - 5 * heightFit)];
    self.textfield.delegate = self;
    self.textfield.borderStyle = 3;
    self.textfield.backgroundColor = [Path colorWithRed:185 green:214 blue:229];
    self.textfield.placeholder = @"  🔍请输入关键字";
    [self addSubview:self.textfield];
    
    self.button = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width - 70 * widthFit, 5 * heightFit, 50 * widthFit, self.frame.size.height - 5 * heightFit)];
    //self.button.backgroundColor = [Path colorWithRed:185 green:214 blue:229];
    [self.button setTitle:@"确定" forState:UIControlStateNormal];
    [self.button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.button];
}

//- (void)textFieldDidEndEditing:(UITextField *)textField
//{
//    [self.delegate sendWithTextWhenDidChange:textField.text];
//}
//

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
     [self.delegate sendWithTextWhenDidChange:string];
    return YES;
}



- (void)button:(UIButton *)button
{
    [self.target performSelector:self.action withObject:self.textfield];
}

- (void)dealloc
{
    [_button release];
    [_textfield release];
    [super dealloc];
}



@end
